package com.itheima;

import com.itheima.intercepter.DemoIntercepter;
import com.itheima.intercepter.LoginCheckIntercepter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration  //类似@Component，声明当前类为配置类
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginCheckIntercepter loginCheckIntercepter;

    @Autowired
    private DemoIntercepter demoIntercepter;
    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册拦截器");
        //registry.addInterceptor(demoIntercepter).addPathPatterns("/**");//添加拦截器并设置拦截路径
        //addPathPatterns设置要拦截什么路径，excludePathPatternspa排除要拦截的路径
       // registry.addInterceptor(demoIntercepter).addPathPatterns("/**").excludePathPatterns("/login");
        registry.addInterceptor(loginCheckIntercepter).addPathPatterns("/**");//添加拦截器并设置拦截路径,默认拦截所有
    }



}
